<?php
require_once "core/initialize.php";
require_once "includes/header.php";

$user = new User();
$msg = "";

$thisLink = URL;
$root = "http://localhost/cookingclubapp/";
if ($thisLink == "/cookingclubapp/activation.php" || $thisLink == "/cookingclubapp/activation.php/") {	
	Redirect::to(404);
	
}elseif ($thisLink) {

	if (!empty($_GET['activation_code']) && isset($_GET['activation_code'])) {
		
		$code = escape($_GET['activation_code']);

		$tableuser = DB::getInstance()->query(" SELECT id FROM users WHERE activation='$code' ");


		if($tableuser->count() > 0)
		{

			$tableuser = DB::getInstance()->query(" SELECT id FROM users WHERE activation='$code' and status='0' ");
			
			if($tableuser->count() == 1)
				{	

					$updatestatus = DB::getInstance()->query(" UPDATE users SET status='1' WHERE activation='$code' ");
	    			$msg = "Your account is activated <br/> <a href=". $root .">Click here to login.</a>";	
	    		}
	   	 		else
	   	 		{
					$msg = "Your account is already active, no need to activate again";
	    		}

	    }
	    else
	    {
			$msg = "Wrong activation code.";
	    }

	}


}

?>

<div class="section group">
	<div class="column div_1_of_3"></div>
	<div class="column div_1_of_3 activate-wrapper">
		 <?php echo $msg; ?>
	</div>
	<div class="column div_1_of_3"></div>
</div>	


<?php require_once "includes/footer.php"; ?>


